<template>
<div class="proAnalysis">
    <component-title :title-text="'盈亏分析'"></component-title>
    <div class="button">
    <div class="left" @click='tabSelect(0)' :class="{'activeBlue':selectedIndex==0,'activeWhite':selectedIndex==1}">股票盈亏</div>
    <div class="right" @click='tabSelect(1)' :class="{'activeBlue':selectedIndex==1,'activeWhite':selectedIndex==0}">理财盈亏</div>
  </div>

  <top3 :time-index="fathertime" :category="selectedIndex" :type="0"></top3>
  <top3 :time-index="fathertime" :category="selectedIndex" :type="1"></top3>

</div>
</template>

<script>
import Top3 from './Top3'
import Title from '@/components/Title'


export default {
  props: ['fathertime', 'tData', 'JMP','assetStat'],
  data() {
    return {
      selectedIndex: 0,
      setProIndex: 0,
      clickStatus: 0
    }
  },
  created() {
    this.setProIndex = this.$store.state.proAnalysisIndex;
    let myHref = window.location.href
    if (myHref.indexOf('location=lcyk') != -1) {
      this.setProIndex = 1
    }
    this.tabSelect(this.setProIndex)
  },
  watch:{
    assetStat:function(){
      this.setProIndex = this.$store.state.proAnalysisIndex;
      let myHref = window.location.href
      if (myHref.indexOf('location=lcyk') != -1) {
        this.setProIndex = 1
      }
      this.tabSelect(this.setProIndex)
    }
  },
  components: {
    'component-title':Title,
    Top3
  },
  methods: {
    tabSelect(index) {
      this.selectedIndex = index;

      this.$store.dispatch('setProAnalysisIndex', index);
      if (this.clickStatus == 1 && index == 0) {
        TDAPP.onEvent('002013', '');
        TDAPP.send();
        this.clickStatus = 0
      }
      if (this.clickStatus == 0 && index == 1) {
        TDAPP.onEvent('002014', '');
        TDAPP.send();
        this.clickStatus = 1
      }
    }
  }
}
</script>
<style scoped>
.proAnalysis{
  margin-top: 15px;
  background: #fff;
  padding-top: 40px;
}
</style>
